<template>
  <!-- 租客信息详情 -->
  <div>
    <!-- 轮播 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in houseDetail.houseImage" :key="item">
        <img :src="'http://192.168.3.63:8085' + item" alt="" />
      </van-swipe-item>
    </van-swipe>
    <!-- 房屋信息 -->
    <homeData :showImg="false" :homeData="houseDetail"></homeData>
    <!-- info -->
    <div class="info">
      <div>
        <div>
          <span class="infoTitel">装修</span>
          <psan>{{ houseDetail.renovationType }}</psan>
        </div>
        <div style="margin: 10px 0">
          <span class="infoTitel">电梯</span>
          <psan>{{ houseDetail.isElevator == "N" ? "无" : "有" }}</psan>
        </div>
        <div>
          <span class="infoTitel">发布</span> <psan>{{ houseDetail.createTime }}</psan>
        </div>
      </div>
      <div>
        <div style="margin-bottom: 10px">
          <span class="infoTitel">供暖</span>
          <psan>{{ houseDetail.isHots == "N" ? "无" : "有" }}</psan>
        </div>
        <div>
          <span class="infoTitel">类型</span> <psan>{{ houseDetail.houseType }}</psan>
        </div>
      </div>
    </div>
    <!-- address -->
    <div class="cardBox">
      <div class="title mb-20">租房地址</div>
      <span class="infoTitel font-14">地址</span>
      <span class="font-14">{{ houseDetail.address }}</span>
    </div>
    <!-- 房源描述 -->
    <div class="cardBox">
      <div class="title mb-20">房源描述</div>
      <div :class="['font-14', isShow ? '' : 'h200']">
        {{ houseDetail.propertyDescription }}
      </div>
      <div
        class="lookA"
        @click="isShow = !isShow"
        v-if="houseDetail.propertyDescription.length > 200"
      >
        {{ isShow ? "收起" : "查看更多" }}
      </div>
    </div>

    <div class="btn_box">
      <div class="Btns">
        <van-button
          class="del"
          round
          block
          type="primary"
          native-type="submit"
          @click="delBaseInfo"
        >
          删除
        </van-button>
        <van-button
          class="sub"
          round
          block
          type="primary"
          native-type="submit"
          @click="updateBaseInfo"
        >
          修改
        </van-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import homeData from "@/components/homeData/index.vue";
import rentalApi from "@/api/rental.js";
import houseApi from "@/api/house.js";
import { useRoute, useRouter } from "vue-router";
import { showConfirmDialog, showToast } from "vant";

const route = useRoute();
const router = useRouter();
const isShow = ref(false);
const houseDetail = ref({});
/**
 * 获取详情
*/
const getDetail = async () => {
  try {
    const res = await rentalApi.getHouseDetail(route.query.rentId);
    console.log(res.data.data);
    houseDetail.value = res.data.data;
    houseDetail.value.houseImage = houseDetail.value.img.split(",");
  } catch (error) {
    console.log(error);
  }
};
getDetail();


// 删除按钮提交事件
const delBaseInfo = () => {
  //删除操作
  showConfirmDialog({
    title: "删除",
    message: "确认删除该条数据吗？"
  }).then(async () => {
      let res = await houseApi.delRent(route.query.rentId);
      console.log("---del---", res);
      if (res.data.code == 200 && res.data.msg == "操作成功") {
        showToast("删除成功");
        setTimeout(() => {
          router.push({
            path: "/rental",
          });
        }, 1200);
      }
  }).catch(() => {})
}
const updateBaseInfo = () => {
  router.push({
    path: '/tenantUpdate',
    query: {
      rentId: route.query.rentId
    }
  })
}
</script>

<style lang="scss" scoped>
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  text-align: center;
  height: 216px;
  img {
    width: 100%;
    height: 100%;
  }
}

.info {
  background-color: #ffffff;
  margin: 15px;
  display: flex;
  border-radius: 15px;
  padding: 20px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;

  .infoTitel {
    color: #666;
    margin-right: 10px;
  }
}

.btn_box {
  position: absolute;
  width: 100%;
  bottom: 0;
  background-color: #fff;
  margin-top: 20px;
  padding: 15px 16px;
  display: flex;
  border: none;
  .Btns {
    width: 100%;
    display: flex;
    .del {
      flex: 3;
      background: linear-gradient(90deg, #f2724d 0%, #ff9576 99%);
    }
    .sub {
      flex: 5;
      margin-left: 20px;
    }
  }
}
</style>
